package com.ruoyi.factorydata.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.factorydata.domain.InventoryReceiptInfo;
import com.ruoyi.factorydata.domain.dto.ModelInventoryPrintDTO;
import com.ruoyi.factorydata.domain.dto.ProductInventoryPrintDetailDTO;
import com.ruoyi.factorydata.service.IInventoryReceiptInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 入库单信息Controller
 *
 * @author ruoyi
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/warehouse/inventoryReceipt")
public class InventoryReceiptInfoController extends BaseController {
    @Autowired
    private IInventoryReceiptInfoService inventoryReceiptInfoService;

    /**
     * 查询入库单信息列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:inventoryReceipt:list')")
    @GetMapping("/list")
    public TableDataInfo list(InventoryReceiptInfo inventoryReceiptInfo) {
        startPage();
        List<InventoryReceiptInfo> list = inventoryReceiptInfoService.selectInventoryReceiptInfoList(inventoryReceiptInfo);
        return getDataTable(list);
    }

    /**
     * 导出入库单信息列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:inventoryReceipt:export')")
    @Log(title = "入库单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InventoryReceiptInfo inventoryReceiptInfo) {
        List<InventoryReceiptInfo> list = inventoryReceiptInfoService.selectInventoryReceiptInfoList(inventoryReceiptInfo);
        ExcelUtil<InventoryReceiptInfo> util = new ExcelUtil<InventoryReceiptInfo>(InventoryReceiptInfo.class);
        util.exportExcel(response, list, "入库单信息数据");
    }

    /**
     * 获取入库单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:inventoryReceipt:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(inventoryReceiptInfoService.selectInventoryReceiptInfoById(id));
    }

    /**
     * 获取入库单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:modelInventory:print')")
    @GetMapping(value = "print/{id}")
    public ModelInventoryPrintDTO getPrintInfo(@PathVariable("id") Long id) {
        return inventoryReceiptInfoService.getPrintInfo(id);
    }
    /**
     * 获取入库单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:inventoryReceipt:print')")
    @GetMapping(value = "print/product/{id}")
    public ProductInventoryPrintDetailDTO getProductPrintInfo(@PathVariable("id") Long id) {
        return inventoryReceiptInfoService.getProductPrintInfo(id);
    }
    /**
     * 新增入库单信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:inventoryReceipt:add')")
    @Log(title = "入库单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InventoryReceiptInfo inventoryReceiptInfo) {
        return toAjax(inventoryReceiptInfoService.insertInventoryReceiptInfo(inventoryReceiptInfo));
    }

    /**
     * 修改入库单信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:inventoryReceipt:edit')")
    @Log(title = "入库单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InventoryReceiptInfo inventoryReceiptInfo) {
        return toAjax(inventoryReceiptInfoService.updateInventoryReceiptInfo(inventoryReceiptInfo));
    }

    /**
     * 删除入库单信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:inventoryReceipt:remove')")
    @Log(title = "入库单信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(inventoryReceiptInfoService.deleteInventoryReceiptInfoByIds(ids));
    }
}
